import type { Commit, LocatedObject, TreeEntry } from "./git/types.ts"; import { log, objectAt, type PathChange, pathHistory } from "./git/walk.ts"; import { detectLanguage, languageGroup } from "./languages.ts"; import { paginate } from "./pagination.tsx"; import { canonical, encodePath, href, kindAtTip, type Site, type View } from "./route.ts"; import { humanSize, identityDate, looksBinary, looksGenerated, plural, utf8 } from "./util.ts"; const TREE = 0o040000; const SYMLINK = 0o120000; const GITLINK = 0o160000; const HISTORY_PREFETCH = 25; const kindOf = (entry: TreeEntry) => entry.mode & 0o170000; async function entriesAt(site: Site, commit: Commit, path: string[]): Promise { const object = await objectAt(site.repo, commit.tree, path); if (!object || (object.mode & 0o170000) !== TREE) throw new Error(`${path.join("/")} is not a tree`); return site.repo.tree(object.oid); } /** `a/b/c` when `a` holds only `b`, which holds only `c`: a chain of lone * directories reads better as one link than as three clicks */ async function collapseLoneDirs(site: Site, entry: TreeEntry): Promise { const names = [entry.name]; let oid = entry.oid; for (;;) { const [only, ...rest] = await site.repo.tree(oid); if (rest.length > 0 || !only || kindOf(only) !== TREE) return names; names.push(only.name); oid = only.oid; } } /** the same shape as the static topbar, minus the ref switcher: the commit * panel above already says which commit this is */ export async function topbar(site: Site, view: View, stats: string[], actions: Node[] = []): Promise { const { name } = site; const { kind, oid, path } = view; const crumbs = (